﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using System.ComponentModel;
using Arch.Samples.Model;
using Arch.Common.Reflection;
using Arch.Samples.RiaServices.Infrastructure;

namespace Arch.Samples.RiaServices.Controls
{
    public partial class Form : ChildWindow
    {
        public static Form Create(object entity, object viewModel, object content)
        {
            return new Form { DataContext = new EditViewModel(entity, viewModel), FormContainer = { Content = content } };
        }


        public Form()
        {
            InitializeComponent();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        public object CurrentItem { get { return ((EditViewModel)DataContext).CurrentItem; } }

        //    public DataTemplate DataTemplate
        //    {
        //        get { return (DataTemplate)GetValue(DataTemplateProperty); }
        //        set { SetValue(DataTemplateProperty, value); }
        //    }

        //    public static readonly DependencyProperty DataTemplateProperty =
        //        DependencyProperty.Register("DataTemplate", typeof(DataTemplate), typeof(Form), new PropertyMetadata(null));

        //    public object Current
        //    {
        //        get { return (object)GetValue(CurrentProperty); }
        //        set { SetValue(CurrentProperty, value); }
        //    }

        //    public static readonly DependencyProperty CurrentProperty =
        //        DependencyProperty.Register("Current", typeof(object), typeof(Form), new PropertyMetadata(null, new PropertyChangedCallback(CurrentChanged)));


        //    private static void CurrentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        //    {
        //        if (args.NewValue is IEditableObject)
        //        {
        //            (args.NewValue as IEditableObject).BeginEdit();
        //        }

        //        if (args.OldValue is IEditableObject)
        //        {
        //            (args.OldValue as IEditableObject).EndEdit();
        //        }
        //    }

        //    public ObservableCollection<Category> Categories
        //    {
        //        get { return (ObservableCollection<Category>)GetValue(CategoriesProperty); }
        //        set { SetValue(CategoriesProperty, value); }
        //    }

        //    // Using a DependencyProperty as the backing store for Categories.  This enables animation, styling, binding, etc...
        //    public static readonly DependencyProperty CategoriesProperty =
        //        DependencyProperty.Register("Categories", typeof(ObservableCollection<Category>), typeof(Form), new PropertyMetadata(null));
        //}
    }

}